//
//  AppManager.m
//  rn
//
//  Created by 牛冬冬 on 2018/3/28.
//  Copyright © 2018年 Jevons-niu. All rights reserved.
//

#import "AppManager.h"
#import <UIKit/UIKit.h>

@interface CYLBaseNavigationController : UINavigationController
@end

@implementation CYLBaseNavigationController

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
    }
    [super pushViewController:viewController animated:animated];
}

@end


#import "HomeViewController.h"
#import "TypeViewController.h"
#import "MineViewController.h"

@interface AppManager ()
@property (nonatomic, readwrite, strong) CYLTabBarController * tabBarController;
@end

@implementation AppManager
static AppManager *manager;
static dispatch_once_t onceToken;

+ (instancetype)share
{
    dispatch_once(&onceToken, ^{
        manager = [[self alloc] init];
        [manager setupViewControllers];
    });
    return manager;
}

+ (void)removeShare
{
    onceToken = 0;
    // 只有置成0,GCD才会认为它从未执行过.它默认为0.这样才能保证下次再次调用shareInstance的时候,再次创建对象.
    manager = nil;
}
    

- (void)setupViewControllers
{
    HomeViewController *home = [[HomeViewController alloc] init];
    UIViewController *homeVC = [[CYLBaseNavigationController alloc] initWithRootViewController:home];
    
    TypeViewController *type = [[TypeViewController alloc] init];
    UIViewController *typeVC = [[CYLBaseNavigationController alloc] initWithRootViewController:type];
    
    MineViewController *mine = [[MineViewController alloc] init];
    UIViewController *mineVC = [[CYLBaseNavigationController alloc] initWithRootViewController:mine];
    
    
    CYLTabBarController *tabBarController = [[CYLTabBarController alloc] init];
    [self customizeTabBarForController:tabBarController];
    
    [tabBarController setViewControllers:@[homeVC, typeVC, mineVC]];
    self.tabBarController = tabBarController;
}

/*
 *
 在`-setViewControllers:`之前设置TabBar的属性，
 *
 */
- (void)customizeTabBarForController:(CYLTabBarController *)tabBarController
{
    
    NSDictionary *dict1 = @{
                            CYLTabBarItemTitle : @"首页",
                            CYLTabBarItemImage : @"tab_home_nor",
                            CYLTabBarItemSelectedImage : @"tab_home_sel",
                            };
    NSDictionary *dict2 = @{
                            CYLTabBarItemTitle : @"分类",
                            CYLTabBarItemImage : @"tab_type_nor",
                            CYLTabBarItemSelectedImage : @"tab_type_sel",
                            };
    NSDictionary *dict3 = @{
                            CYLTabBarItemTitle : @"我的",
                            CYLTabBarItemImage : @"tab_mine_nor",
                            CYLTabBarItemSelectedImage : @"tab_mine_sel",
                            };
    
    NSArray *tabBarItemsAttributes = @[dict1, dict2, dict3];
    tabBarController.tabBarItemsAttributes = tabBarItemsAttributes;
}




@end
